<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件委派</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            background-color: aqua;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
            align-content: space-around;
        }
        .item{
            width: 120px;
            height: 120px;
            background-color: bisque;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
    <script>
        const box=document.querySelector(".box");
        //事件委派
        box.onclick=(e)=>{
            if(e.target.classList.contains("item")){
                e.target.style.backgroundColor="red";
            }
        }
    </script>
</body>
</html>